package cn.fintecher.pangolin.entity.elastic;

import cn.fintecher.pangolin.common.annotation.ExcelAnno;
import cn.fintecher.pangolin.common.enums.BillType;
import cn.fintecher.pangolin.common.utils.Constants;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;

import java.util.Date;
import java.util.Objects;

/**
 * @Auther: xiaqun
 * @Description: 还款记录模型
 * @Date: 14:24 2019/10/8
 */

@Data
@Document(indexName = Constants.PAYMENT_RECORD_MODEL, type = Constants.PAYMENT_RECORD_MODEL, shards = 1, replicas = 0)
@ApiModel(value = "还款记录模型", description = "还款记录模型")
public class PaymentRecordModel {
    @Id
    @ApiModelProperty(value = "主键ID")
    private String id;

    @ApiModelProperty(value = "案件编号")
    @ExcelAnno(cellName = "案件编号", fieldDataType = ExcelAnno.FieldDataType.STRING, fieldType = ExcelAnno.FieldType.BILL)
    private String caseNumber;

    @ApiModelProperty(value = "批次号")
    private String batchNumber;

    @ApiModelProperty(value = "卡号")
    @ExcelAnno(cellName = "卡号", fieldDataType = ExcelAnno.FieldDataType.STRING, fieldType = ExcelAnno.FieldType.BILL)
    private String cardNo;

    @ApiModelProperty(value = "客户姓名")
    @ExcelAnno(cellName = "客户姓名", fieldDataType = ExcelAnno.FieldDataType.STRING, fieldType = ExcelAnno.FieldType.BILL)
    private String personalName;

    @ApiModelProperty(value = "委托方ID")
    private String principalId;

    @ApiModelProperty(value = "委托方名称")
    private String principalName;

    @ApiModelProperty(value = "还款日期")
    @ExcelAnno(cellName = "还款日期", fieldDataType = ExcelAnno.FieldDataType.DATE, fieldType = ExcelAnno.FieldType.BILL)
    private Date paymentDate;

    @ApiModelProperty(value = "还款金额")
    @ExcelAnno(cellName = "还款金额", fieldDataType = ExcelAnno.FieldDataType.DOUBLE, fieldType = ExcelAnno.FieldType.BILL)
    private Double paymentAmt;

    @ApiModelProperty(value = "备注")
    @ExcelAnno(cellName = "备注", fieldDataType = ExcelAnno.FieldDataType.STRING, fieldType = ExcelAnno.FieldType.BILL)
    private String remark;

    @ApiModelProperty(value = "账单类型(0:委前还款,1:还款)")
    @ExcelAnno(cellName = "账单类型(0:委前还款,1:还款)", fieldDataType = ExcelAnno.FieldDataType.INTEGER, fieldType = ExcelAnno.FieldType.BILL)
    private Integer type;

    @ApiModelProperty(value = "账单类型")
    private BillType billType;

    @ApiModelProperty(value = "撤销标记 0-未撤销 1-已撤销")
    private Integer flag = 0;

    public void process() {
        if (Objects.nonNull(this.type)) {
            if (this.type == 0) {
                this.billType = BillType.PRE_REPAYMENT;
            } else if (this.type == 1) {
                this.billType = BillType.REPAYMENT;
            }
        }
    }
}
